package org.millioncall.yueyoga.admin.export;

import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.millioncall.yueyoga.admin.model.Chedule;

public class ClassExportTemplate extends AbstractExcelExportTemplate {
	private List<Chedule> records;
	String[] titles = new String[] { "班级名称", "老师名称", "助教名称", "场地名称", "开课时间"};

	public ClassExportTemplate(List<Chedule> records) {
		this.records = records;
	}

	@Override
	public String[] getSheetNames() {
		return new String[] { "班级信息表" };
	}

	@Override
	public String[][] getTitles() {
		return new String[][] { titles };
	}

	@Override
	protected void buildBody(int sheetIndex) {
		Sheet sheet = getSheet(sheetIndex);
		int startIndex = this.getBodyStartIndex(sheetIndex);
		for (int i = 0; i < this.records.size(); i++) {
			Chedule record = this.records.get(i);

			Row row = sheet.createRow(i + startIndex);
			row.setHeight((short) 300);
			int index = 0;
			String week = "";
			Integer intweek = record.getWeek();
			String str = "";
			if(intweek == null){
				week = "";
			}else{
				str = intweek.toString();
			}
			if("1".equals(str)){
				week = "周一";
			}else if("2".equals(str)){
				week = "周二";
			}else if("3".equals(str)){
				week = "周三";
			}else if("4".equals(str)){
				week = "周四";
			}else if("5".equals(str)){
				week = "周五";
			}else if("6".equals(str)){
				week = "周六";
			}else if("7".equals(str)){
				week = "周日";
			}
		    String startTime = record.getStarttime();
		    String starTime = "";
		    if(startTime == null){
		    	starTime = "";
		    }else{
		    	starTime = record.getStarttime().toString();
		    }
		    String endTime = record.getEndtime();
		    String enTime = "";
		    if(endTime == null){
		    	enTime = "";
		    }else{
		    	enTime = record.getEndtime().toString();
		    }
			createStyledCell(row, index++, record.getClazz() == null ? "" : record.getClazz().getName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getTeacher() == null ? "" : record.getTeacher().getName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getAssistant() == null ? "" : record.getAssistant().getName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getPlace() == null ? "" : record.getPlace().getName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, week+""+starTime+"~"+enTime, this.bodyRowStyle);
		}
	}

	@Override
	public String[] getCaptions() {
		return new String[] { "班级信息表" };
	}
}
